#include "./command.hpp"
#include "./baseCommandReceiver.hpp"

using namespace qbe::undoRedoT;

Command::Command() : auto_delete_receiver(true) {}

Command::~Command() {
  if (auto_delete_receiver && receiver) {
    delete receiver;
    receiver = nullptr;
  }
}

bool Command::Execute() {
  if (receiver) {
    return receiver->Action(false);
  }

  return false;
}

bool Command::Unexecute() {
  if (receiver) {
    return receiver->Action(true);
  }
  return false;
}

void Command::SetReceiver(BaseCommandReceiver* _receiver, bool _auto_delete_reveiver) {
  receiver = _receiver;
  auto_delete_receiver = _auto_delete_reveiver;
}
